/**
 * 二分查找
 * 有序数组里每次都检查中间元素向下取整
 * 要查找的元素与中间元素比较
 * 若果要查找的元素小于中间元素 往小了找
 * 若果要查找的元素大于中间元素 往大了找
 * 若果要查找的元素等于中间元素 就返回索引
 */
function binary_search(list, item) {
    let low = 0
    let high = list.length - 1
    let mid, guess

    while (low <= high) {
        mid = Math.floor((low + high) / 2)
        guess = list[mid]
        if (item < guess) {
            high = mid - 1
        } else if (item == guess) {
            return mid
        } else {
            low = mid + 1
        }
    }
    return 'none'
}
let my_list = [1, 3, 5, 7, 9]


console.log(binary_search(my_list, 7));
console.log(binary_search(my_list, 11));